package com.example.service;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.example.mall.Order;
import com.example.util.MockData;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.weaver.ast.Or;
import org.springframework.stereotype.Component;

/**
 * @ClassName OrderServiceImpl
 * @Description TODO
 * @Author: XMK
 * @Date: 2020/5/12 19:02
 * @Version: 1.0
 */
@Component
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Override
    @SentinelResource(value = "orderRes", blockHandler = "selectOrderByIdBlockHandler")
    public Order selectOrderById(String orderId) {

        return MockData.getOrder(orderId);
    }

    public Order selectOrderByIdBlockHandler(BlockException e) {
        log.error("V2流量控制：", e);
        Order order = new Order();
        order.setOrderNo("限流订单");
        return order;
    }

}
